package com.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class GsonUtils {
	private Gson mGson = new GsonBuilder().disableHtmlEscaping().create();

	private GsonUtils() {

	}

	private static class SinglGson {
		private static GsonUtils sGsonUtils = new GsonUtils();
	}

	public static GsonUtils getintance() {
		return SinglGson.sGsonUtils;
	}

	/**
	 * 将对象转为字符串
	 * 
	 * @param t
	 *            转为JSON数据的对象
	 * @param str
	 *            忽略转换的字段
	 * @return 返回字符串
	 */
	public <T> String toJson(T t, String[] str) {
		if (t == null) {
			return "{}";
		} else {
			return mGson.toJson(t);
		}
	}

}
